package com.test.services;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.test.comment.FightBean;
import com.test.comment.SingerBean;
import com.test.comment.UservoteBean;
import com.test.dao.VoteDao;

@Service
public class VoteServices {

	Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	VoteDao voteDao;
	
	//查找比赛
	public FightBean FindFight() {
		FightBean a = voteDao.SelectVote();
		return a;
	}
	//获取歌手信息
	public SingerBean findSinger(int sid) {
		SingerBean singer =voteDao.SelectSinger(sid);
		return singer;
	}
	
	//查询投票表里是否有该用户(是，阻止投票；否，添加数据)
	public String Selectuservote(String usercode,int rid,int sid) {
		
		System.out.println("====services start=====");
		
		
		String a = voteDao.SelectUserVote(usercode,rid);
		System.out.println("====SelectUserVote start=====");
		
		if(a!=null) {
			return "1";//该用户已为此比赛投票
		}else {
			UservoteBean uservoteBean= new UservoteBean();
			uservoteBean.setUsercode(usercode);
			uservoteBean.setRid(rid);
			uservoteBean.setSid(sid);
			voteDao.InsertUser(uservoteBean);
			
			return "2";//插入成功
			
		}
	}
	
}
